<?php

function d($obj, $die = false)
{
	echo '<pre>';
	print_r($obj);
	echo '</pre>';
	
	if ($die == true)
	{
		die();
	}
}

function lfirst($str)
{
	if (!is_numeric($str) && !is_string($str)) {
		throw 'Error in "lcfirst" function: argument has undefined type';
	} else {
		return strtolower(substr($str, 0, 1)) . substr($str, 1);
	}
}

function sendMimeMail($name_from, $email_from, $name_to, $email_to, $data_charset, $send_charset, $subject, $body)
{
	$to = mimeHeaderEncode($name_to, $data_charset, $send_charset) . ' <' . $email_to . '>';
	$subject = mimeHeaderEncode($subject, $data_charset, $send_charset);
	
	if (strval($name_from) != '') {
		$from =  mimeHeaderEncode($name_from, $data_charset, $send_charset)
                     .' <' . $email_from . '>';
	} else {
		$from = $email_from;
	}
  
	if($data_charset != $send_charset) {
    	$body = iconv($data_charset, $send_charset, $body);
  	}
  	
  	$headers  = "From: $from\r\n";
  	$headers .= "Content-type: text/html; charset=$send_charset\r\n";
  	$headers .= 'X-Mailer: PHP/' . phpversion() . "\r\n";

  	return mail($to, $subject, $body, $headers);
}

function mimeHeaderEncode($str, $data_charset, $send_charset)
{
	if($data_charset != $send_charset) {
    	$str = iconv($data_charset, $send_charset, $str);
  	}
  	
  	return '=?' . $send_charset . '?B?' . base64_encode($str) . '?=';
}